import request from "@/utils/request";
import { API_ENDPOINTS } from "@/config/api";

// 用户统计信息接口
export interface UserStatistics {
  total_sessions: number;
  completed_sessions: number;
  total_training_time: number;
  average_performance: number;
  achievements_count: number;
  current_streak: number;
}

// 用户能力值接口
export interface UserAbility {
  ability_type: string;
  ability_name: string;
  current_level: number;
  experience_points: number;
  next_level_points: number;
}

// 更新用户资料参数
export interface UpdateProfileParams {
  username?: string;
  bio?: string;
}

// 修改密码参数
export interface ChangePasswordParams {
  current_password: string;
  password: string;
  password_confirmation: string;
}

// 用户相关API
export const userApi = {
  // 获取用户资料
  getProfile() {
    return request.get(API_ENDPOINTS.USER.PROFILE);
  },

  // 更新用户资料
  updateProfile(params: UpdateProfileParams) {
    return request.put(API_ENDPOINTS.USER.PROFILE, params);
  },

  // 上传头像
  uploadAvatar(formData: FormData) {
    return request.upload(API_ENDPOINTS.USER.AVATAR, formData);
  },

  // 修改密码
  changePassword(params: ChangePasswordParams) {
    return request.put(API_ENDPOINTS.USER.PASSWORD, params);
  },

  // 获取用户统计信息
  getUserStatistics(userId: number) {
    return request.get<UserStatistics>(API_ENDPOINTS.USER.STATISTICS(userId));
  },

  // 获取用户能力值
  getUserAbilities(userId: number) {
    return request.get<UserAbility[]>(API_ENDPOINTS.USER.ABILITIES(userId));
  },

  // 获取能力值历史
  getAbilitiesHistory(
    userId: number,
    params?: {
      ability_type?: string;
      days?: number;
    }
  ) {
    return request.get(API_ENDPOINTS.USER.ABILITIES_HISTORY(userId), {
      params,
    });
  },

  // 获取用户收藏的角色
  getFavoriteCharacters(userId: number) {
    return request.get(API_ENDPOINTS.USER.FAVORITE_CHARACTERS(userId));
  },
};
